package com.xxd.spring.boot.demo.hexinglei.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxd.spring.boot.demo.wubolin.Result;
import com.xxd.spring.boot.demo.wubolin.entity.Teacher;
import com.xxd.spring.boot.demo.wubolin.exception.MyException;
import com.xxd.spring.boot.demo.wubolin.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @RequestMapping("/add")
    public Result add(@RequestBody Teacher teacher) throws MyException {
        teacherService.add(teacher);
        return new Result().success();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Teacher teacher) throws MyException {
        teacherService.update(teacher);
        return new Result().success();
    }

    @RequestMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) throws MyException {
        teacherService.delete(id);
        return new Result().success();
    }

    @RequestMapping("/listPage")
    public Result listPage(Page page, @RequestBody Map<String,Object> params) throws MyException {
        IPage respage = teacherService.listPage(page,params);
        return new Result().success().setData(respage);
    }

    @RequestMapping("/list")
    public Result list(@RequestBody Map<String,Object> param) throws MyException {
        List<Teacher> list = teacherService.list(param);
        return new Result().success().setData(list);
    }

    @RequestMapping("/tea/{id}")
    public Result tea(@PathVariable("id") Integer id) throws MyException {
        Teacher tea = teacherService.tea(id);
        return new Result().success().setData(tea);
    }

    @RequestMapping("/all")
    public Result all(){
        List<Teacher> list = teacherService.all();
        return new Result().success().setData(list);
    }
}
